<include file="public@header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:url('goods/front')}">{:lang('ADMIN_GOODS_FRONT')}</a></li>
			<li><a href="{:url('goods/addfront')}">{:lang('商品添加')}</a></li>
		</ul>
         <div>
       	<form  class="well form-search" action="{:url('Goods/index')}" method="post">
        <label>{:lang('GOODS_NAME')}: 
        	<input type="text" class="form-control" name="goods_name" placeholder="请输入商品名称"value="{:input('request.goods_name')}" >
        </label>
        <input type="submit" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:url('Goods/index')}">清空</a>
        </form>
        </div>
		<form action="{:url('Rbac/listorders')}" method="post">
        	<php>$status = array('1' => '下架', '0' => '上架');</php>
            <!--库存小于10 用红色显示-->
			<table class="table table-hover table-bordered">
				<thead>
					<tr>
                        <th width="3%">ID</th>
						<th width="15%">{:lang('GOODS_NAME')}</th>
                        <th width="10%">{:lang('GOODS_CATE')}</th>
                        <th width="10%">{:lang('PRICE')}</th>
                        <th width="10%">{:lang('SUPPLIER')}</th>
                        <th width="12%">{:lang('STOCK')}</th>
                        <th width="10%">{:lang('STOREROOM')}</th>
						<th width="15%">{:lang('ADD_TIME')}</th>
						<th width="15%">{:lang('ACTIONS')}</th>
					</tr>
				</thead>
				<tbody>
					<foreach name="results" item="vo">
					<tr>
						<td>{$vo.id}</td>
						<td>{$vo.goods_name}</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>{$vo['sale']}</td>
						<td>{$vo['sale']}</td>
						<td><php>echo date('Y-m-d H:i:s', $vo['add_time'])</php></td>
						<td>
							<a href="{:url('Goods/edit',array('id'=>$vo['id'],'type'=>$vo['type']))}">{:lang('EDIT')}</a>
							|	
							<a href="{:url('Goods/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                        </td>
					</tr>
					</foreach>
				</tbody>
			</table>
			<div class="pagination">{$page}</div>
		</form>

	</div>
	<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
    <script type="text/javascript">
	$("select[name='type']").change(function(){
				var mark = $("select[name='type']").val();
				if(mark==1){
					var type='exchange';
				}else if(mark==2){
					var type='normal';}
				else{
					var type="all";
					}
					
				// 拼接AJAX请求
				$.ajax({
					url		: "{:url('Cate/getParentByAjax')}", 
					type	: "post", 
					dataType: "json", 
					data	: {'mark':type, 'Ajax': 1}, 
					success : function(result){
						$("select[name='cate_p_id'] > option").remove();
						$("select[name='cate'] > option").remove();
						var html = "<option value='0'>请选择分类</option>";
						$.each(result, function(i, n){
							html += "<option value='" + n.id + "'>" + n.cate_name + "</option>";
						});
						$("select[name='cate_p_id']").html(html);
					},
					error	: function(){
						alert("服务器内部错误，请联系系统管理员");
					}
				});
			});
	$(document).ready(function(e) {
		// 商品分类变更查询
		$("select[name='cate_p_id']").change(function(){
			var selectVal = $(this).val();
			$(this).next().hide().find("option").not(":first").remove();
			if(selectVal != ''){
				$.ajax({
					url		: "{:url('Cate/getCateAjax')}", 
					type	: "post", 
					dataType: "json", 
					data	: {'id': selectVal, 'Ajax': 1}, 
					success : function(result){
						var html = "";
						$.each(result, function(i, n){
							html += "<option value='" + n.id + "'>" + n.cate_name + "</option>";
						});
						$("select[name='cate_p_id']").next().show().append(html);
					},
					error	: function(){
						alert("服务器内部错误，请联系系统管理员");
					}
				});
			}
		});
	});
		</script>
</body>
</html>